﻿define(function (require) {
    require('model/Workitem');
    window.WorkitemList = Backbone.Collection.extend({
        model: Workitem,
        comparator: function (e) {
            return -e.get('StatusValue');
        },
        reset: function (e) {
            var _workimteList = this;
            this._reset();
            if (e) {
                this.add(e);
                for (var i in this.models) {
                    var workitem = this.models[i];
                    workitem.bind('finished', function (args) {
                        var workitemModel = _workimteList.getByCid(args[0]);
                        _workimteList.remove(workitemModel);
                        _workimteList.trigger('message', args[1])
                    });
                    workitem.bind('confirmed', function (args) {
                        var workitemModel = _workimteList.getByCid(args[0]);
                        workitemModel.set({ "StatusValue": 0,
                                            "CommandText": "完成",
                                            "CommandClass": "green"
                                        });
                       
                        _workimteList.trigger('message', args[1])
                    });
                }
            }
        }
    });
});